from enum import Enum

from app.serve.wtrees.base import BaseModel
from sqlalchemy import (
    Column,
    Index,
    Integer,
    String,
    text,
    SmallInteger,
)


class PermissionModel(BaseModel):
    __tablename__ = "wtrees_permission"
    __table_args__ = (Index("name_module", "name", "module", unique=True),)

    class StateEnum(Enum):
        OFF = 0  # 关闭
        ON = 1  # 开启

    id = Column(Integer(), primary_key=True)
    name = Column(String(60), nullable=False, comment="权限名称，例如：访问首页")
    module = Column(String(50), nullable=False, comment="权限所属模块，例如：人员管理")
    state = Column(
        SmallInteger(), nullable=False, server_default=text(str(StateEnum.ON.value))
    )
